package com.core.common.utils;

import org.springframework.util.StringUtils;

/**
 * @program: YJ-admin
 * @description: 字符串转换工具
 * @author: honglei
 * @create: 2022-06-09 17:35
 */
public class SqlColumnConvertUtil {


    public static  String strCleanUp(String str){
        if (!StringUtils.hasLength(str)){
            return "";
        }
        str=str.replace(" ","");
        if (str.startsWith("_")){
            str=str.replaceFirst("_","");
        }
        str=str.toLowerCase();
        return str;
    }



    public static String convertToAttributeType(String str){
        StringBuffer sb = new StringBuffer(strCleanUp(str));
        int count = sb.indexOf("_");
        while(count!=0){
            int num = sb.indexOf("_",count);
            count = num + 1;
            if(num != -1){
                char ss = sb.charAt(count);
                if (ss > 96 && ss < 123 ){
                    char ia = (char) (ss - 32);
                    sb.replace(count , count + 1,ia + "");
                }
            }
        }
        String result = sb.toString().replaceAll("_","");
        return result;
    }

    public static  String convertToClassType(String str){
       String strResult = convertToAttributeType(str);
        if (!StringUtils.hasText(strResult)){
            return "";
        }
        char ss = strResult.charAt(0);
        char ia = (char) (ss - 32);
        if (ss > 96 && ss < 123 ){
            strResult=strResult.replaceFirst(""+ss,""+ia);
        }
        return strResult;
    }

    public static void main(String[] args) {
        System.out.println(convertToAttributeType("__asdd32_sfdsf_DDF__Ddfdf"));
        System.out.println();
        System.out.println(convertToClassType("__adsd32_sfdsf_DDF__Ddfdf"));
    }


}
